# Copyright © 2017 Intel Corporation

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

subdir('program')
subdir('main')

# files shared between classic mesa and gallium mesa
files_libmesa_common = files(
  'program/arbprogparse.c',
  'program/arbprogparse.h',
  'program/ir_to_mesa.cpp',
  'program/ir_to_mesa.h',
  'program/prog_cache.c',
  'program/prog_cache.h',
  'program/prog_execute.c',
  'program/prog_execute.h',
  'program/prog_instruction.c',
  'program/prog_instruction.h',
  'program/prog_noise.c',
  'program/prog_noise.h',
  'program/prog_opt_constant_fold.c',
  'program/prog_optimize.c',
  'program/prog_optimize.h',
  'program/prog_parameter.c',
  'program/prog_parameter.h',
  'program/prog_parameter_layout.c',
  'program/prog_parameter_layout.h',
  'program/prog_print.c',
  'program/prog_print.h',
  'program/program.c',
  'program/program.h',
  'program/programopt.c',
  'program/programopt.h',
  'program/program_parse_extra.c',
  'program/program_parser.h',
  'program/prog_statevars.c',
  'program/prog_statevars.h',
  'program/symbol_table.c',
  'program/symbol_table.h',
  'program/prog_to_nir.c',
  'program/prog_to_nir.h',
  'main/accum.c',
  'main/accum.h',
  'main/api_arrayelt.c',
  'main/api_arrayelt.h',
  'main/api_exec.h',
  'main/arbprogram.c',
  'main/arbprogram.h',
  'main/arrayobj.c',
  'main/arrayobj.h',
  'main/atifragshader.c',
  'main/atifragshader.h',
  'main/attrib.c',
  'main/attrib.h',
  'main/barrier.c',
  'main/barrier.h',
  'main/bbox.c',
  'main/bbox.h',
  'main/blend.c',
  'main/blend.h',
  'main/blit.c',
  'main/blit.h',
  'main/bufferobj.c',
  'main/bufferobj.h',
  'main/buffers.c',
  'main/buffers.h',
  'main/clear.c',
  'main/clear.h',
  'main/clip.c',
  'main/clip.h',
  'main/colormac.h',
  'main/colortab.c',
  'main/colortab.h',
  'main/compute.c',
  'main/compute.h',
  'main/condrender.c',
  'main/condrender.h',
  'main/config.h',
  'main/conservativeraster.c',
  'main/conservativeraster.h',
  'main/context.c',
  'main/context.h',
  'main/convolve.c',
  'main/convolve.h',
  'main/copyimage.c',
  'main/copyimage.h',
  'main/cpuinfo.c',
  'main/cpuinfo.h',
  'main/dd.h',
  'main/debug.c',
  'main/debug.h',
  'main/debug_output.c',
  'main/debug_output.h',
  'main/depth.c',
  'main/depth.h',
  'main/dlist.c',
  'main/dlist.h',
  'main/draw.c',
  'main/draw.h',
  'main/drawpix.c',
  'main/drawpix.h',
  'main/drawtex.c',
  'main/drawtex.h',
  'main/draw_validate.c',
  'main/draw_validate.h',
  'main/enable.c',
  'main/enable.h',
  'main/enums.h',
  'main/errors.c',
  'main/errors.h',
  'main/eval.c',
  'main/eval.h',
  'main/execmem.c',
  'main/extensions.c',
  'main/extensions.h',
  'main/extensions_table.c',
  'main/extensions_table.h',
  'main/externalobjects.c',
  'main/externalobjects.h',
  'main/fbobject.c',
  'main/fbobject.h',
  'main/feedback.c',
  'main/feedback.h',
  'main/ff_fragment_shader.cpp',
  'main/ffvertex_prog.c',
  'main/ffvertex_prog.h',
  'main/fog.c',
  'main/fog.h',
  'main/format_pack.h',
  'main/format_unpack.h',
  'main/formatquery.c',
  'main/formatquery.h',
  'main/formats.c',
  'main/formats.h',
  'main/format_utils.c',
  'main/format_utils.h',
  'main/framebuffer.c',
  'main/framebuffer.h',
  'main/get.c',
  'main/get.h',
  'main/genmipmap.c',
  'main/genmipmap.h',
  'main/getstring.c',
  'main/glformats.c',
  'main/glformats.h',
  'main/glspirv.c',
  'main/glspirv.h',
  'main/glthread.c',
  'main/glthread.h',
  'main/glthread_bufferobj.c',
  'main/glthread_draw.c',
  'main/glthread_get.c',
  'main/glthread_list.c',
  'main/glthread_marshal.h',
  'main/glthread_shaderobj.c',
  'main/glthread_varray.c',
  'main/glheader.h',
  'main/hash.c',
  'main/hash.h',
  'main/hint.c',
  'main/hint.h',
  'main/histogram.c',
  'main/histogram.h',
  'main/image.c',
  'main/image.h',
  'main/mesa_private.h',
  'main/light.c',
  'main/light.h',
  'main/lines.c',
  'main/lines.h',
  'main/macros.h',
  'main/matrix.c',
  'main/matrix.h',
  'main/mipmap.c',
  'main/mipmap.h',
  'main/menums.h',
  'main/mtypes.h',
  'main/multisample.c',
  'main/multisample.h',
  'main/objectlabel.c',
  'main/objectlabel.h',
  'main/objectpurge.c',
  'main/objectpurge.h',
  'main/pack.c',
  'main/pack.h',
  'main/pbo.c',
  'main/pbo.h',
  'main/performance_monitor.c',
  'main/performance_monitor.h',
  'main/performance_query.c',
  'main/performance_query.h',
  'main/pipelineobj.c',
  'main/pipelineobj.h',
  'main/pixel.c',
  'main/pixel.h',
  'main/pixelstore.c',
  'main/pixelstore.h',
  'main/pixeltransfer.c',
  'main/pixeltransfer.h',
  'main/points.c',
  'main/points.h',
  'main/polygon.c',
  'main/polygon.h',
  'main/program_binary.c',
  'main/program_binary.h',
  'main/program_resource.c',
  'main/program_resource.h',
  'main/querymatrix.c',
  'main/querymatrix.h',
  'main/queryobj.c',
  'main/queryobj.h',
  'main/rastpos.c',
  'main/rastpos.h',
  'main/readpix.c',
  'main/readpix.h',
  'main/remap.c',
  'main/remap.h',
  'main/renderbuffer.c',
  'main/renderbuffer.h',
  'main/robustness.c',
  'main/samplerobj.c',
  'main/samplerobj.h',
  'main/scissor.c',
  'main/scissor.h',
  'main/shaderapi.c',
  'main/shaderapi.h',
  'main/shaderimage.c',
  'main/shaderimage.h',
  'main/shaderobj.c',
  'main/shaderobj.h',
  'main/shader_query.cpp',
  'main/shared.c',
  'main/shared.h',
  'main/spirv_extensions.c',
  'main/spirv_extensions.h',
  'main/state.c',
  'main/state.h',
  'main/stencil.c',
  'main/stencil.h',
  'main/syncobj.c',
  'main/syncobj.h',
  'main/texcompress.c',
  'main/texcompress_astc.cpp',
  'main/texcompress_astc.h',
  'main/texcompress_bptc.c',
  'main/texcompress_bptc.h',
  'main/texcompress_cpal.c',
  'main/texcompress_cpal.h',
  'main/texcompress_etc.c',
  'main/texcompress_etc.h',
  'main/texcompress_etc_tmp.h',
  'main/texcompress_fxt1.c',
  'main/texcompress_fxt1.h',
  'main/texcompress.h',
  'main/texcompress_rgtc.c',
  'main/texcompress_rgtc.h',
  'main/texcompress_s3tc.c',
  'main/texcompress_s3tc.h',
  'main/texenv.c',
  'main/texenv.h',
  'main/texenvprogram.h',
  'main/texformat.c',
  'main/texformat.h',
  'main/texgen.c',
  'main/texgen.h',
  'main/texgetimage.c',
  'main/texgetimage.h',
  'main/teximage.c',
  'main/teximage.h',
  'main/texobj.c',
  'main/texobj.h',
  'main/texparam.c',
  'main/texparam.h',
  'main/texstate.c',
  'main/texstate.h',
  'main/texstorage.c',
  'main/texstorage.h',
  'main/texstore.c',
  'main/texstore.h',
  'main/texturebindless.c',
  'main/texturebindless.h',
  'main/textureview.c',
  'main/textureview.h',
  'main/transformfeedback.c',
  'main/transformfeedback.h',
  'main/uniform_query.cpp',
  'main/uniforms.c',
  'main/uniforms.h',
  'main/varray.c',
  'main/varray.h',
  'main/vdpau.c',
  'main/vdpau.h',
  'main/version.c',
  'main/version.h',
  'main/viewport.c',
  'main/viewport.h',
  'main/vtxfmt.c',
  'main/vtxfmt.h',
  'main/es1_conversion.c',
  'main/es1_conversion.h',
  'math/m_debug.h',
  'math/m_debug_clip.c',
  'math/m_debug_norm.c',
  'math/m_debug_util.h',
  'math/m_debug_xform.c',
  'math/m_eval.c',
  'math/m_eval.h',
  'math/m_matrix.c',
  'math/m_matrix.h',
  'math/m_trans_tmp.h',
  'math/m_translate.c',
  'math/m_translate.h',
  'math/m_vector.c',
  'math/m_vector.h',
  'vbo/vbo_attrib.h',
  'vbo/vbo_attrib_tmp.h',
  'vbo/vbo_context.c',
  'vbo/vbo_exec_api.c',
  'vbo/vbo_exec.c',
  'vbo/vbo_exec_draw.c',
  'vbo/vbo_exec_eval.c',
  'vbo/vbo_exec.h',
  'vbo/vbo.h',
  'vbo/vbo_init_tmp.h',
  'vbo/vbo_minmax_index.c',
  'vbo/vbo_noop.c',
  'vbo/vbo_noop.h',
  'vbo/vbo_save_api.c',
  'vbo/vbo_save.c',
  'vbo/vbo_save_draw.c',
  'vbo/vbo_save.h',
  'vbo/vbo_save_loopback.c',
  'vbo/vbo_util.h',
  'x86/common_x86.c',
)

# mesa files
files_libmesa_classic = files(
  'math/m_clip_tmp.h',
  'math/m_copy_tmp.h',
  'math/m_dotprod_tmp.h',
  'math/m_norm_tmp.h',
  'math/m_xform.c',
  'math/m_xform.h',
  'math/m_xform_tmp.h',
  'tnl/t_context.c',
  'tnl/t_context.h',
  'tnl/t_draw.c',
  'tnl/tnl.h',
  'tnl/t_pipeline.c',
  'tnl/t_pipeline.h',
  'tnl/t_rebase.c',
  'tnl/t_split.c',
  'tnl/t_split_copy.c',
  'tnl/t_split.h',
  'tnl/t_split_inplace.c',
  'tnl/t_vb_cliptmp.h',
  'tnl/t_vb_fog.c',
  'tnl/t_vb_light.c',
  'tnl/t_vb_lighttmp.h',
  'tnl/t_vb_normals.c',
  'tnl/t_vb_points.c',
  'tnl/t_vb_program.c',
  'tnl/t_vb_render.c',
  'tnl/t_vb_rendertmp.h',
  'tnl/t_vb_texgen.c',
  'tnl/t_vb_texmat.c',
  'tnl/t_vb_vertex.c',
  'tnl/t_vertex.c',
  'tnl/t_vertex_generic.c',
  'tnl/t_vertex.h',
  'tnl/t_vertex_sse.c',
  'tnl/t_vp_build.c',
  'tnl/t_vp_build.h',
  'swrast/s_aaline.c',
  'swrast/s_aaline.h',
  'swrast/s_aalinetemp.h',
  'swrast/s_aatriangle.c',
  'swrast/s_aatriangle.h',
  'swrast/s_aatritemp.h',
  'swrast/s_alpha.c',
  'swrast/s_alpha.h',
  'swrast/s_atifragshader.c',
  'swrast/s_atifragshader.h',
  'swrast/s_bitmap.c',
  'swrast/s_blend.c',
  'swrast/s_blend.h',
  'swrast/s_blit.c',
  'swrast/s_chan.h',
  'swrast/s_clear.c',
  'swrast/s_context.c',
  'swrast/s_context.h',
  'swrast/s_copypix.c',
  'swrast/s_depth.c',
  'swrast/s_depth.h',
  'swrast/s_drawpix.c',
  'swrast_setup/ss_tritmp.h',
  'swrast_setup/ss_vb.h',
  'swrast_setup/swrast_setup.h',
  'swrast/s_feedback.c',
  'swrast/s_feedback.h',
  'swrast/s_fog.c',
  'swrast/s_fog.h',
  'swrast/s_fragprog.c',
  'swrast/s_fragprog.h',
  'swrast/s_lines.c',
  'swrast/s_lines.h',
  'swrast/s_linetemp.h',
  'swrast/s_logic.c',
  'swrast/s_logic.h',
  'swrast/s_masking.c',
  'swrast/s_masking.h',
  'swrast/s_points.c',
  'swrast/s_points.h',
  'swrast/s_renderbuffer.c',
  'swrast/s_renderbuffer.h',
  'swrast/s_span.c',
  'swrast/s_span.h',
  'swrast/s_stencil.c',
  'swrast/s_stencil.h',
  'swrast/s_texcombine.c',
  'swrast/s_texcombine.h',
  'swrast/s_texfetch.c',
  'swrast/s_texfetch.h',
  'swrast/s_texfetch_tmp.h',
  'swrast/s_texfilter.c',
  'swrast/s_texfilter.h',
  'swrast/s_texrender.c',
  'swrast/s_texture.c',
  'swrast/s_triangle.c',
  'swrast/s_triangle.h',
  'swrast/s_tritemp.h',
  'swrast/swrast.h',
  'swrast/s_zoom.c',
  'swrast/s_zoom.h',
  'swrast_setup/ss_context.c',
  'swrast_setup/ss_context.h',
  'swrast_setup/ss_triangle.c',
  'swrast_setup/ss_triangle.h',
  'drivers/common/driverfuncs.c',
  'drivers/common/driverfuncs.h',
  'drivers/common/meta_blit.c',
  'drivers/common/meta_generate_mipmap.c',
  'drivers/common/meta.c',
  'drivers/common/meta.h',
  'x86/x86_xform.c',
  'x86/3dnow.c',
  'x86/sse.c',
  'x86/rtasm/x86sse.c',
  'x86/rtasm/x86sse.h',
  'sparc/sparc.c',
  'x86-64/x86-64.c',
)

files_libmesa_gallium = files(
  'state_tracker/st_atifs_to_nir.c',
  'state_tracker/st_atifs_to_nir.h',
  'state_tracker/st_atom_array.c',
  'state_tracker/st_atom_atomicbuf.c',
  'state_tracker/st_atom_blend.c',
  'state_tracker/st_atom.c',
  'state_tracker/st_atom_clip.c',
  'state_tracker/st_atom_constbuf.c',
  'state_tracker/st_atom_constbuf.h',
  'state_tracker/st_atom_depth.c',
  'state_tracker/st_atom_framebuffer.c',
  'state_tracker/st_atom.h',
  'state_tracker/st_atom_list.h',
  'state_tracker/st_atom_image.c',
  'state_tracker/st_atom_msaa.c',
  'state_tracker/st_atom_pixeltransfer.c',
  'state_tracker/st_atom_rasterizer.c',
  'state_tracker/st_atom_sampler.c',
  'state_tracker/st_atom_scissor.c',
  'state_tracker/st_atom_shader.c',
  'state_tracker/st_atom_stipple.c',
  'state_tracker/st_atom_storagebuf.c',
  'state_tracker/st_atom_tess.c',
  'state_tracker/st_atom_texture.c',
  'state_tracker/st_atom_viewport.c',
  'state_tracker/st_cb_bitmap.c',
  'state_tracker/st_cb_bitmap.h',
  'state_tracker/st_cb_bitmap_shader.c',
  'state_tracker/st_cb_blit.c',
  'state_tracker/st_cb_blit.h',
  'state_tracker/st_cb_bufferobjects.c',
  'state_tracker/st_cb_bufferobjects.h',
  'state_tracker/st_cb_clear.c',
  'state_tracker/st_cb_clear.h',
  'state_tracker/st_cb_compute.c',
  'state_tracker/st_cb_compute.h',
  'state_tracker/st_cb_condrender.c',
  'state_tracker/st_cb_condrender.h',
  'state_tracker/st_cb_copyimage.c',
  'state_tracker/st_cb_copyimage.h',
  'state_tracker/st_cb_drawpixels.c',
  'state_tracker/st_cb_drawpixels.h',
  'state_tracker/st_cb_drawpixels_shader.c',
  'state_tracker/st_cb_drawtex.c',
  'state_tracker/st_cb_drawtex.h',
  'state_tracker/st_cb_eglimage.c',
  'state_tracker/st_cb_eglimage.h',
  'state_tracker/st_cb_fbo.c',
  'state_tracker/st_cb_fbo.h',
  'state_tracker/st_cb_feedback.c',
  'state_tracker/st_cb_feedback.h',
  'state_tracker/st_cb_flush.c',
  'state_tracker/st_cb_flush.h',
  'state_tracker/st_cb_memoryobjects.c',
  'state_tracker/st_cb_memoryobjects.h',
  'state_tracker/st_cb_msaa.c',
  'state_tracker/st_cb_msaa.h',
  'state_tracker/st_cb_perfmon.c',
  'state_tracker/st_cb_perfmon.h',
  'state_tracker/st_cb_perfquery.c',
  'state_tracker/st_cb_perfquery.h',
  'state_tracker/st_cb_program.c',
  'state_tracker/st_cb_program.h',
  'state_tracker/st_cb_queryobj.c',
  'state_tracker/st_cb_queryobj.h',
  'state_tracker/st_cb_rasterpos.c',
  'state_tracker/st_cb_rasterpos.h',
  'state_tracker/st_cb_readpixels.c',
  'state_tracker/st_cb_readpixels.h',
  'state_tracker/st_cb_strings.c',
  'state_tracker/st_cb_strings.h',
  'state_tracker/st_cb_semaphoreobjects.c',
  'state_tracker/st_cb_semaphoreobjects.h',
  'state_tracker/st_cb_syncobj.c',
  'state_tracker/st_cb_syncobj.h',
  'state_tracker/st_cb_texturebarrier.c',
  'state_tracker/st_cb_texturebarrier.h',
  'state_tracker/st_cb_texture.c',
  'state_tracker/st_cb_texture.h',
  'state_tracker/st_cb_viewport.c',
  'state_tracker/st_cb_viewport.h',
  'state_tracker/st_cb_xformfb.c',
  'state_tracker/st_cb_xformfb.h',
  'state_tracker/st_context.c',
  'state_tracker/st_context.h',
  'state_tracker/st_copytex.c',
  'state_tracker/st_copytex.h',
  'state_tracker/st_debug.c',
  'state_tracker/st_debug.h',
  'state_tracker/st_draw.c',
  'state_tracker/st_draw_feedback.c',
  'state_tracker/st_draw.h',
  'state_tracker/st_extensions.c',
  'state_tracker/st_extensions.h',
  'state_tracker/st_format.c',
  'state_tracker/st_format.h',
  'state_tracker/st_gen_mipmap.c',
  'state_tracker/st_gen_mipmap.h',
  'state_tracker/st_gl_api.h',
  'state_tracker/st_glsl_to_ir.cpp',
  'state_tracker/st_glsl_to_ir.h',
  'state_tracker/st_glsl_to_nir.cpp',
  'state_tracker/st_glsl_to_tgsi.cpp',
  'state_tracker/st_glsl_to_tgsi.h',
  'state_tracker/st_glsl_to_tgsi_array_merge.cpp',
  'state_tracker/st_glsl_to_tgsi_array_merge.h',
  'state_tracker/st_glsl_to_tgsi_private.cpp',
  'state_tracker/st_glsl_to_tgsi_private.h',
  'state_tracker/st_glsl_to_tgsi_temprename.cpp',
  'state_tracker/st_glsl_to_tgsi_temprename.h',
  'state_tracker/st_manager.c',
  'state_tracker/st_manager.h',
  'state_tracker/st_nir.h',
  'state_tracker/st_nir_builtins.c',
  'state_tracker/st_nir_lower_builtin.c',
  'state_tracker/st_nir_lower_tex_src_plane.c',
  'state_tracker/st_pbo.c',
  'state_tracker/st_pbo.h',
  'state_tracker/st_program.c',
  'state_tracker/st_program.h',
  'state_tracker/st_sampler_view.c',
  'state_tracker/st_sampler_view.h',
  'state_tracker/st_scissor.c',
  'state_tracker/st_scissor.h',
  'state_tracker/st_shader_cache.c',
  'state_tracker/st_shader_cache.h',
  'state_tracker/st_texture.c',
  'state_tracker/st_texture.h',
  'state_tracker/st_tgsi_lower_depth_clamp.c',
  'state_tracker/st_tgsi_lower_depth_clamp.h',
  'state_tracker/st_tgsi_lower_yuv.c',
  'state_tracker/st_tgsi_lower_yuv.h',
  'state_tracker/st_util.h',
  'state_tracker/st_vdpau.c',
  'state_tracker/st_vdpau.h',
)

inc_libmesa_asm = []
if with_asm_arch == 'x86'
  files_libmesa_common += files(
    'x86/assyntax.h',
    'x86/clip_args.h',
    'x86/norm_args.h',
    'x86/xform_args.h',
    'x86/common_x86_asm.S',
    'x86/common_x86_asm.h',
    'x86/common_x86_features.h',
    'x86/x86_xform.h',
    'x86/x86_xform2.S',
    'x86/x86_xform3.S',
    'x86/x86_xform4.S',
    'x86/x86_cliptest.S',
    'x86/mmx.h',
    'x86/mmx_blend.S',
    'x86/mmx_blendtmp.h',
    'x86/3dnow.h',
    'x86/3dnow_xform1.S',
    'x86/3dnow_xform2.S',
    'x86/3dnow_xform3.S',
    'x86/3dnow_xform4.S',
    'x86/sse.h',
    'x86/sse_xform1.S',
    'x86/sse_xform2.S',
    'x86/sse_xform3.S',
    'x86/sse_xform4.S',
    'x86/sse_normal.S',
    'x86/read_rgba_span_x86.S',
  )
  inc_libmesa_asm = include_directories('x86')
elif with_asm_arch == 'x86_64'
  files_libmesa_common += files('x86-64/x86-64.h', 'x86-64/xform4.S')
  inc_libmesa_asm = include_directories('x86-64')
elif with_asm_arch == 'sparc'
  files_libmesa_common += files(
    'sparc/sparc_clip.S',
    'sparc/norm.S',
    'sparc/xform.S',
  )
  inc_libmesa_asm = include_directories('sparc')
endif

format_fallback_c = custom_target(
  'format_fallback.c',
  input : ['main/format_fallback.py', 'main/formats.csv'],
  output : 'format_fallback.c',
  command : [prog_python, '@INPUT0@', '@INPUT1@', '@OUTPUT@'],
  depend_files : files('main/format_parser.py'),
)

get_hash_h = custom_target(
  'get_hash.h',
  input : ['main/get_hash_generator.py', gl_and_es_api_files],
  output : 'get_hash.h',
  command : [prog_python, '@INPUT0@', '-f', '@INPUT1@'],
  depend_files : files('main/get_hash_params.py'),
  capture : true,
)

foreach x : [['format_info.h', 'format_info.py']]
  files_libmesa_common += custom_target(
    x[0],
    input : ['main/@0@'.format(x[1]), 'main/formats.csv'],
    output : x[0],
    command : [prog_python, '@INPUT0@', '@INPUT1@'],
    depend_files : files('main/format_parser.py'),
    capture : true,
  )
endforeach

files_libmesa_common += [
  mesa_lex,
  program_parse_tab,
  main_api_exec_c,
  main_enums_c,
  format_fallback_c,
  get_hash_h,
  main_marshal_generated_h,
  main_dispatch_h,
  ir_expression_operation_h,
  main_remap_helper_h,
  sha1_h,
] + main_marshal_generated_c
files_libmesa_gallium += [
  ir_expression_operation_h,
  sha1_h,
]

if with_sse41
  libmesa_sse41 = static_library(
    'mesa_sse41',
    files('main/streaming-load-memcpy.c', 'main/sse_minmax.c'),
    c_args : [c_msvc_compat_args, sse41_args],
    include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
    gnu_symbol_visibility : 'hidden',
  )
else
  libmesa_sse41 = []
endif

_mesa_windows_args = []
if with_platform_windows
  _mesa_windows_args += [
    '-D_GDI32_',    # prevent gl* being declared __declspec(dllimport) in MS headers
    '-DBUILD_GL32'  # declare gl* as __declspec(dllexport) in Mesa headers
  ]
  if not with_shared_glapi
    # prevent _glapi_* from being declared __declspec(dllimport)
    _mesa_windows_args += '-D_GLAPI_NO_EXPORTS'
  endif
endif

libmesa_common = static_library(
  'mesa_common',
  files_libmesa_common,
  c_args : [c_msvc_compat_args, _mesa_windows_args],
  cpp_args : [cpp_msvc_compat_args, _mesa_windows_args],
  gnu_symbol_visibility : 'hidden',
  include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux, inc_libmesa_asm, include_directories('main')],
  dependencies : [idep_nir_headers, idep_mesautil],
  build_by_default : false,
)

libmesa_classic = static_library(
  'mesa_classic',
  files_libmesa_classic,
  c_args : [c_msvc_compat_args],
  cpp_args : [cpp_msvc_compat_args],
  gnu_symbol_visibility : 'hidden',
  include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux, inc_libmesa_asm, include_directories('main')],
  link_with : [libmesa_common, libglsl, libmesa_sse41],
  dependencies : [idep_nir_headers, idep_mesautil],
  build_by_default : false,
)

libmesa_gallium = static_library(
  'mesa_gallium',
  files_libmesa_gallium,
  c_args : [c_msvc_compat_args, _mesa_windows_args],
  cpp_args : [cpp_msvc_compat_args, _mesa_windows_args],
  gnu_symbol_visibility : 'hidden',
  include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux, inc_libmesa_asm, include_directories('main')],
  link_with : [libmesa_common, libglsl, libmesa_sse41],
  dependencies : [idep_nir_headers, dep_vdpau, idep_mesautil],
  build_by_default : false,
)

subdir('drivers/dri')
if with_glx == 'xlib'
  subdir('drivers/x11')
endif
if with_tests
  subdir('main/tests')
endif
